/**
 * 用户档案里面自学记录
 */

function student_self() {
    var _this = this;
    var page;
    _this.page_size = 10;

    _this.init = function (page_self) {
        page = page_self;
        _this.initTable_self();
    };

    _this.initTable_self = function () {
        var list_url = appPath + "/popup/studySelfList";
        page.init("study_self_info_form", list_url, "study_self_info_table", "study_self_info_page", 1, _this.page_size);
        page.goPage(1);
        page.list = function (dataList) {
            var len = dataList.length;
            var inner = "", item;
            // 组装数据
            for (var i = 0; i < len; i++) {
                item = dataList[i];
                var classHour = item['class_hour'];
                var studyTime = item['study_time'];
                inner += '<tr>';
                inner += '<td>' + (i + 1) + '</td>';
                inner += '<td>' + item['course_name'] + '</td>';
                inner += '<td>' + classHour + '</td>';
                inner += '<td>' + TimeUtil.getHouAndMinAndSec(studyTime) + '</td>';
                var progress;
                var status;
                var classHourSec = Number(classHour) * 60;
                studyTime = Number(studyTime);
                if (studyTime >= classHourSec) {
                    progress = '100%';
                    status = '已完成';
                } else {
                    progress = getPercent(studyTime, classHourSec);
                    status = '未完成';
                }


                inner += '<td>' + progress + '</td>';
                inner += '<td>' + status +'</td>';
                inner += '</tr>';
            }
            return inner;
        }
    };

    _this.searchSelf = function () {
        $("#courseName").val($.trim($("#courseName").val()));
        _this.initTable_self();
    };

    _this.searchAllSelf = function () {
        $("#courseName").val("");
        _this.initTable_self();
    };
}
var student_self = new student_self();

/**
 * 计算两数百分比
 * @param num1
 * @param num2
 * @returns {*}
 */
function getPercent(num1, num2) {
    num1 = parseFloat(num1);
    num2 = parseFloat(num2);
    if (isNaN(num1) || isNaN(num2)) {
        return '/';
    }

    return num2 <= 0 ? '100%' : (Math.round(num1 / num2 * 10000) / 100.00 + '%');
}